from django.dispatch import receiver

from apps.notification.models import ProviderNotificationSetting, ProviderNotification, ClientNotification
from django.dispatch import Signal

from apps.notification.types import NotificationTypes, ClientNotificationTypes

client_message = Signal()
provider_message = Signal()


# @receiver(client_message)
# def add_client_message_notification(sender, instance, **kwargs):
#     content = "{} {} has sent you a message".format(instance.client.first_name, instance.client.last_name)
#     setting = ProviderNotificationSetting.objects.filter().first()
#     if setting.client_messages:
#         ProviderNotification.objects.create(
#             content=content,
#             notification_type=NotificationTypes.CLIENT_MESSAGES.value,
#         )


@receiver(provider_message)
def add_provider_message_notification(sender, instance, user, **kwargs):
    content = "{} {} has sent you a message".format(user.first_name, user.last_name)
    ClientNotification.objects.create(
            content=content,
            notification_type=ClientNotificationTypes.PROVIDER_MESSAGES.value,
            client=instance.client
        )
